var th,
    url = 'Tiexi',
    tabId = window.location.hash,
    // 缩写列表
    idLib = [
        {
            $id: $('#TX_DailySPHTarget'),
            val: 'D.SPH T.'
        },
        {
            $id: $('#TX_CurrentSPH'),
            val: 'C. SPH'
        },
        {
            $id: $('#TX_SPHDeviation'),
            val: 'SPH Dev.'
        },
        {
            $id: $('#TX_DailyUptimeTarget'),
            val: 'D. Uptime T.'
        },
        {
            $id: $('#TX_CurrentUptime'),
            val: 'C. Uptime'
        },
        {
            $id: $('#TX_UptimeDeviation'),
            val: 'Uptime Dev.'
        },
        {
            $id: $('#DD_DailySPHTarget'),
            val: 'D.SPH T.'
        },
        {
            $id: $('#DD_CurrentSPH'),
            val: 'C. SPH'
        },
        {
            $id: $('#DD_SPHDeviation'),
            val: 'SPH Dev.'
        },
        {
            $id: $('#DD_DailyUptimeTarget'),
            val: 'D. Uptime T.'
        },
        {
            $id: $('#DD_CurrentUptime'),
            val: 'C. Uptime'
        },
        {
            $id: $('#DD_UptimeDeviation'),
            val: 'Uptime Dev.'
        },
        {
            $id: $('#GP1930'),
            val: '1930'
        },
        {
            $id: $('#GP1960'),
            val: '1960'
        },
        {
            $id: $('#GP1961'),
            val: '1961'
        },
        {
            $id: $('#GP1965'),
            val: '1965'
        }

    ];
var setBackground = function () {
    var width = $(window).width();
    var height = $(window).height();
    var contentHeight = parseInt($('#viewStage').css('height'));
    if (contentHeight < height) {
        $('.com-bg').css('height', height);
    }
    else {
        $('.com-bg').css('height', contentHeight);
    }

    if (width < 450) {
        $.each(idLib, function (index, item) {
            item.$id.html(item.val);
        });
    }
};


var lib = [
    //assembly
    {
        $elm: $("#Net_OEE_F0"),
        bdId: 'A821OEE_F0_Hourly Output Control',
        flag: 11,
        threshold: 64.5
    },
    {
        $elm: $("#Net_OEE_F1"),
        bdId: 'A821OEE_F1_Hourly Output Control',
        flag: 11,
        threshold: 64.5
    },
    {
        $elm: $("#Net_OEE_F2"),
        bdId: 'A821OEE_F2_Hourly Output',
        flag: 11,
        threshold: -1
    },
    {
        $elm: $("#Net_OEE_Monthly"),
        bdId: 'A821OEE_Monthly_Hourly Output',
        flag: 11,
        threshold: 64.5
    },
    {
        $elm: $("#CycleTime"),
        bdId: 'A821TLG1._PLC.TVI.Z001',
        flag: 3,
        threshold: 'none'
    },
    {
        $elm: $("#DayTarget_F0"),
        bdId: 'A.CVI.Z067',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#DayTarget_F1"),
        bdId: 'A.CVI.Z066',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#DayTarget_F2"),
        bdId: 'A.CVI.Z061',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#CurrentTarget_F0"),
        bdId: 'A.CVI.Z008',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#CurrentTarget_F1"),
        bdId: 'A821OEE_F1_cur',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#CurrentTarget_F2"),
        bdId: 'A821OEE_F2_cur',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#ActualVolume_F0"),
        bdId: 'A.CVI.Z013',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#ActualVolume_F1"),
        bdId: 'A.CVI.Z015',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#ActualVolume_F2"),
        bdId: 'A.CVI.Z027',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#Deviation_F0"),
        bdId: '',
        flag: 4,
        threshold: 0,
        ida: 'A.CVI.Z013',
        idb: 'A.CVI.Z008'
    },
    {
        $elm: $("#Deviation_F1"),
        bdId: '',
        flag: 4,
        threshold: 0,
        ida: 'A.CVI.Z015',
        idb: 'A821OEE_F1_cur'
    },
    {
        $elm: $("#Deviation_F2"),
        bdId: '',
        flag: 4,
        threshold: 0,
        ida: 'A.CVI.Z027',
        idb: 'A821OEE_F2_cur'
    },
    {
        $elm: $("#F30"),
        bdId: 'apipso72.OSM168',
        flag: 2,
        threshold: 92
    },
    {
        $elm: $("#F35"),
        bdId: 'apipso72.OSM169',
        flag: 2,
        threshold: 92
    },
    {
        $elm: $("#F45"),
        bdId: 'apipso72.OSM170',
        flag: 2,
        threshold: 92
    },
    {
        $elm: $("#F49"),
        bdId: 'apipso72.OSM171',
        flag: 2,
        threshold: 92
    },
    {
        $elm: $("#F52"),
        bdId: 'apipso72.OSM172',
        flag: 2,
        threshold: 92
    },
    //paint shop
    {
        $elm: $("#DayTarget_MPS_IN"),
        bdId: 'P_Conveyor.P_in_daily_target',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#DayTarget_MPS_OUT"),
        bdId: 'P_Conveyor.P_out_daily_target',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#CurrentTarget_MPS_IN"),
        bdId: 'P_Conveyor.P_in_Cur_target',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#CurrentTarget_MPS_OUT"),
        bdId: 'P_Conveyor.P_out_cur_target',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#ActualVolume_MPS_IN"),
        bdId: '',
        flag: 6,
        threshold: 'none',
        ida: '319101Z1._PLC.CVI.M0105',
        idb: '319101Z1._PLC.CVI.M0002'
    },
    {
        $elm: $("#ActualVolume_MPS_OUT"),
        bdId: '319116Z1._PLC.CVI.M0075',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#Deviation_MPS_IN"),
        bdId: '',
        flag: 7,
        threshold: 'none',
        ida: '319101Z1._PLC.CVI.M0105',
        idb: '319101Z1._PLC.CVI.M0002',
        idc: 'P_Conveyor.P_in_Cur_target'
    },
    {
        $elm: $("#Deviation_MPS_OUT"),
        bdId: '',
        flag: 4,
        threshold: 'none',
        ida: '319116Z1._PLC.CVI.M0075',
        idb: 'P_Conveyor.P_out_cur_target'
    },
    {
        $elm: $("#Total_Actual"),
        bdId: 'apipsp72.PPE128',
        flag: 9,
        threshold: 'none'
    },
    {
        $elm: $("#Paint_Body_Actual"),
        bdId: '',
        flag: 8,
        threshold: 'none',
        ida: 'apipsp72.PPE130',
        idb: 'apipso72.EVO358'
    },
    {
        $elm: $("#Body_In_White_Actual"),
        bdId: 'apipsp72.PPE129',
        flag: 1,
        threshold: 30
    },
    {
        $elm: $("#Special_Cars_Actual"),
        bdId: 'apipsp72.PPE1208',
        flag: 10,
        threshold: 'none'
    },
    //body shop
    {
        $elm: $("#DayTarget_UnderBody_LK"),
        bdId: 'DayTarget_UnderBody_LK',
        flag: 5,
        threshold: 'none',
        ida: '3_Daily_Target_LK_UB_F30',
        idb: '3_Daily_Target_LK_UB_F35'
    },
    {
        $elm: $("#DayTarget_UnderBody_LU"),
        bdId: 'DayTarget_UnderBody_LU',
        flag: 5,
        threshold: 'none',
        ida: '3_Daily_Target_F45_GM',
        idb: '3_Daily_Target_F52_GM',
        idc: '3_Daily_Target_F49_GM'
    },
    {
        $elm: $("#DayTarget_Framing_LK"),
        bdId: 'DayTarget_Framing_LK',
        flag: 5,
        threshold: 'none',
        ida: '3_Daily_Target_LK_UB_F30',
        idb: '3_Daily_Target_LK_UB_F35'
    },
    {
        $elm: $("#DayTarget_Framing_LU"),
        bdId: 'DayTarget_Framing_LU',
        flag: 5,
        threshold: 'none',
        ida: '3_Daily_Target_F45_GM',
        idb: '3_Daily_Target_F52_GM',
        idc: '3_Daily_Target_F49_GM',
        idd: '3_Daily_Target_F49P_GM'
    },
    {
        $elm: $("#DayTarget_MetalFinish_LK"),
        bdId: 'DayTarget_MetalFinish_LK',
        flag: 5,
        threshold: 'none',
        ida: '3_Daily_Target_F30_GM',
        idb: '3_Daily_Target_F35_GM'
    },
    {
        $elm: $("#DayTarget_MetalFinish_LU"),
        bdId: 'DayTarget_MetalFinish_LU',
        flag: 5,
        threshold: 'none',
        ida: '3_Daily_Target_F45_GM',
        idb: '3_Daily_Target_F52_GM',
        idc: '3_Daily_Target_F49_GM',
        idd: '3_Daily_Target_F49P_GM',
        ide: '3_Daily_Target_M13_GM'
    },
    {
        $elm: $("#DayTarget_SUM"),
        bdId: '3_Daily_Target_BIW_Total',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#CurrentTarget_UnderBody_LK"),
        bdId: 'CurrentTarget_UnderBody_LK',
        flag: 5,
        threshold: 'none',
        ida: '3_LK_UB_F30_CurrentTargetDay',
        idb: '3_LK_UB_F35_CurrentTargetDay'
    },
    {
        $elm: $("#CurrentTarget_UnderBody_LU"),
        bdId: 'CurrentTarget_UnderBody_LU',
        flag: 5,
        threshold: 'none',
        ida: '3_F45_GM_CurrentTargetDay',
        idb: '3_F52_GM_CurrentTargetDay',
        idc: '3_F49_GM_CurrentTargetDay'
    },
    {
        $elm: $("#CurrentTarget_Framing_LK"),
        bdId: 'CurrentTarget_Framing_LK',
        flag: 5,
        threshold: 'none',
        ida: '3_LK_UB_F30_CurrentTargetDay',
        idb: '3_LK_UB_F35_CurrentTargetDay'
    },
    {
        $elm: $("#CurrentTarget_Framing_LU"),
        bdId: 'CurrentTarget_Framing_LU',
        flag: 5,
        threshold: 'none',
        ida: '3_F45_GM_CurrentTargetDay',
        idb: '3_F52_GM_CurrentTargetDay',
        idc: '3_F49_GM_CurrentTargetDay',
        idd: '3_F49P_GM_CurrentTargetDay'
    },
    {
        $elm: $("#CurrentTarget_MetalFinish_LK"),
        bdId: 'CurrentTarget_MetalFinish_LK',
        flag: 5,
        threshold: 'none',
        ida: '3_F30_GM_CurrentTargetDay',
        idb: '3_F35_GM_CurrentTargetDay'
    },
    {
        $elm: $("#CurrentTarget_MetalFinish_LU"),
        bdId: 'CurrentTarget_MetalFinish_LU',
        flag: 5,
        threshold: 'none',
        ida: '3_F45_GM_CurrentTargetDay',
        idb: '3_F52_GM_CurrentTargetDay',
        idc: '3_F49_GM_CurrentTargetDay',
        idd: '3_F49P_GM_CurrentTargetDay',
        ide: '3_M13_GM_CurrentTargetDay'
    },
    {
        $elm: $("#CurrentTarget_SUM"),
        bdId: '3_BIW_Total_CurrentTargetDay',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#ActualVolume_UnderBody_LK"),
        bdId: 'ActualVolume_UnderBody_LK',
        flag: 5,
        threshold: 'none',
        ida: '3_LK_UB_F30_ActualDay',
        idb: '3_LK_UB_F35_ActualDay'
    },
    {
        $elm: $("#ActualVolume_UnderBody_LU"),
        bdId: 'ActualVolume_UnderBody_LU',
        flag: 5,
        threshold: 'none',
        ida: '3_LU_UB_F45_ActualDay',
        idb: '3_LU_UB_F52_ActualDay',
        idc: '3_LU_UB_F49_ActualDay'
    },
    {
        $elm: $("#ActualVolume_Framing_LK"),
        bdId: 'ActualVolume_Framing_LK',
        flag: 5,
        threshold: 'none',
        ida: '3_LK_FR3_F30_ActualDay',
        idb: '3_LK_FR3_F35_ActualDay'
    },
    {
        $elm: $("#ActualVolume_Framing_LU"),
        bdId: 'ActualVolume_Framing_LU',
        flag: 5,
        threshold: 'none',
        ida: '3_LU_FR3_F45_ActualDay',
        idb: '3_LU_FR3_F52_ActualDay',
        idc: '3_LU_FR3_F49_ActualDay',
        idd: '3_LU_FR3_F49P_ActualDay'
    },
    {
        $elm: $("#ActualVolume_MetalFinish_LK"),
        bdId: 'ActualVolume_MetalFinish_LK',
        flag: 5,
        threshold: 'none',
        ida: '3_F30_ActualDay',
        idb: '3_F35_ActualDay'
    },
    {
        $elm: $("#ActualVolume_MetalFinish_LU"),
        bdId: 'ActualVolume_MetalFinish_LU',
        flag: 5,
        threshold: 'none',
        ida: '3_MF_F45_ActualDay',
        idb: '3_MF_F52_ActualDay',
        idc: '3_MF_F49_ActualDay',
        idd: '3_MF_F49P_ActualDay',
        ide: '3_MF_M13_ActualDay'
    },
    {
        $elm: $("#ActualVolume_SUM"),
        bdId: '3_BIW_Total_ActualDay',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#Deviation_UnderBody_LK"),
        bdId: '',
        flag: 4,
        threshold: 0,
        ida: 'ActualVolume_UnderBody_LK',
        idb: 'CurrentTarget_UnderBody_LK'
    },
    {
        $elm: $("#Deviation_UnderBody_LU"),
        bdId: '',
        flag: 4,
        threshold: 0,
        ida: 'ActualVolume_UnderBody_LU',
        idb: 'CurrentTarget_UnderBody_LU'
    },
    {
        $elm: $("#Deviation_Framing_LK"),
        bdId: '',
        flag: 4,
        threshold: 0,
        ida: 'ActualVolume_Framing_LK',
        idb: 'CurrentTarget_Framing_LK'
    },
    {
        $elm: $("#Deviation_Framing_LU"),
        bdId: '',
        flag: 4,
        threshold: 0,
        ida: 'ActualVolume_Framing_LU',
        idb: 'CurrentTarget_Framing_LU'
    },
    {
        $elm: $("#Deviation_MetalFinish_LK"),
        bdId: '',
        flag: 4,
        threshold: 0,
        ida: 'ActualVolume_MetalFinish_LK',
        idb: 'CurrentTarget_MetalFinish_LK'
    },
    {
        $elm: $("#Deviation_MetalFinish_LU"),
        bdId: '',
        flag: 4,
        threshold: 0,
        ida: 'ActualVolume_MetalFinish_LU',
        idb: 'CurrentTarget_MetalFinish_LU'
    },
    {
        $elm: $("#Deviation_SUM"),
        bdId: '',
        flag: 4,
        threshold: 0,
        ida: '3_BIW_Total_ActualDay',
        idb: '3_BIW_Total_CurrentTargetDay'
    }
];

var libPressTX = [
    {
        $elm: $("#Daily_SPH_target_GP1930"),
        bdId: 'gp1930_daily_sph_target',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#Current_SPH_GP1930"),
        bdId: 'gp1930_current_sph',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#SPH_Deviation_GP1930"),
        bdId: 'gp1930_sph_deviation',
        flag: 2,
        threshold: 0,
        ida: 'gp1930_current_sph',
        idb: 'gp1930_daily_sph_target'
    },
    {
        $elm: $("#Daily_uptime_target_GP1930"),
        bdId: 'gp1930_daily_uptime_target',
        flag: 3,
        threshold: 'none'
    },
    {
        $elm: $("#Current_uptime_GP1930"),
        bdId: 'gp1930_current_uptime',
        flag: 3,
        threshold: 'none'
    },
    {
        $elm: $("#Uptime_deviation_GP1930"),
        bdId: 'gp1930_uptime_deviation',
        flag: 4,
        threshold: 0,
        ida: 'gp1930_current_uptime',
        idb: 'gp1930_daily_uptime_target'
    },
    {
        $elm: $("#Daily_SPH_target_GP1960"),
        bdId: 'gp1960_daily_sph_target',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#Current_SPH_GP1960"),
        bdId: 'gp1960_current_sph',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#SPH_Deviation_GP1960"),
        bdId: 'gp1960_sph_deviation',
        flag: 2,
        threshold: 0,
        ida: 'gp1960_current_sph',
        idb: 'gp1960_daily_sph_target'
    },
    {
        $elm: $("#Daily_uptime_target_GP1960"),
        bdId: 'gp1960_daily_uptime_target',
        flag: 3,
        threshold: 'none'
    },
    {
        $elm: $("#Current_uptime_GP1960"),
        bdId: 'gp1960_current_uptime',
        flag: 3,
        threshold: 'none'
    },
    {
        $elm: $("#Uptime_deviation_GP1960"),
        bdId: 'gp1960_uptime_deviation',
        flag: 4,
        threshold: 0,
        ida: 'gp1960_current_uptime',
        idb: 'gp1960_daily_uptime_target'
    },
    {
        $elm: $("#Daily_SPH_target_GP1961"),
        bdId: 'gp1961_daily_sph_target',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#Current_SPH_GP1961"),
        bdId: 'gp1961_current_sph',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#SPH_Deviation_GP1961"),
        bdId: 'gp1961_sph_deviation',
        flag: 2,
        threshold: 0,
        ida: 'gp1961_current_sph',
        idb: 'gp1961_daily_sph_target'
    },
    {
        $elm: $("#Daily_uptime_target_GP1961"),
        bdId: 'gp1961_daily_uptime_target',
        flag: 3,
        threshold: 'none'
    },
    {
        $elm: $("#Current_uptime_GP1961"),
        bdId: 'gp1961_current_uptime',
        flag: 3,
        threshold: 'none'
    },
    {
        $elm: $("#Uptime_deviation_GP1961"),
        bdId: 'gp1961_uptime_deviation',
        flag: 4,
        threshold: 0,
        ida: 'gp1961_current_uptime',
        idb: 'gp1961_daily_uptime_target'
    }
];

var libPressDD = [
    {
        $elm: $("#Daily_SPH_target_GP1965"),
        bdId: 'gp1965_daily_sph_target',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#Current_SPH_GP1965"),
        bdId: 'gp1965_current_sph',
        flag: 1,
        threshold: 'none'
    },
    {
        $elm: $("#SPH_Deviation_GP1965"),
        bdId: 'gp1965_sph_deviation',
        flag: 2,
        threshold: 0,
        ida: 'gp1965_current_sph',
        idb: 'gp1965_daily_sph_target'
    },
    {
        $elm: $("#Daily_uptime_target_GP1965"),
        bdId: 'gp1965_daily_uptime_target',
        flag: 3,
        threshold: 'none'
    },
    {
        $elm: $("#Current_uptime_GP1965"),
        bdId: 'gp1965_current_uptime',
        flag: 3,
        threshold: 'none'
    },
    {
        $elm: $("#Uptime_deviation_GP1965"),
        bdId: 'gp1965_uptime_deviation',
        flag: 4,
        threshold: 0,
        ida: 'gp1965_current_uptime',
        idb: 'gp1965_daily_uptime_target'
    }
];

//判断数字函数
var is_numberic = function (val) {
    var result = false;
    var pattern = new RegExp("^ *\\-{0,1} *\\d+(\\.\\d+){0,1} *$");
    var valType = typeof val;
    if (valType === 'string' || valType === 'number') {
        result = pattern.test(val)
    }
    return result;
};

//判断背景颜色函数
var judgeBackgroundColor = function (result, threshold, item) {
    var $elm = item.$elm;
    if (threshold !== 'none') {
        if (result < threshold) {
            $elm.css({
                'background': '#FF2700',
                'color': '#fff'
            });
        } else if (result >= threshold) {
            $elm.css({
                'background': '#008000',
                'color': '#fff'
            });
        }
    }
};

var getValue = function (res, item) {
    var result = 0,
        $elm = item.$elm,
        bdId = item.bdId,
        flag = item.flag,
        threshold = item.threshold,
        valA = res[item['ida']],
        valB = res[item['idb']],
        valC = res[item['idc']],
        valD = res[item['idd']],
        valE = res[item['ide']],
        value = res[bdId];

    if (threshold !== 'none') {
        if (value && is_numberic(value) && value < threshold) {
            $elm.css({
                'background': '#FF2700',
                'color': '#fff'
            });
        } else {
            $elm.css({
                'background': '#008000',
                'color': '#fff'
            });
        }
    }
    switch (flag) {
        case 1:
            if (is_numberic(value)) {
                result = parseInt(value);
            } else {
                result = '-';
            }
            break;
        case 2:
            if (is_numberic(value)) {
                result = parseInt(value * 10) / 10 + '%';
            } else {
                result = '-';
            }
            break;
        case 3:
            if (is_numberic(value)) {
                result = parseInt(value * 10) / 10 + 's';
            } else {
                result = '-';
            }
            break;
        case 4:
            if (is_numberic(valA) && is_numberic(valB)) {
                result = valA - valB;
                if (result < 0) {
                    $elm.css({
                        'background': '#FF2700',
                        'color': '#fff'
                    });
                } else {
                    $elm.css({
                        'background': '#008000',
                        'color': '#fff'
                    });
                }
            } else {
                result = "-";
            }
            break;
        case 5:
            // console.log('well');
            valC ? valC : valC = 0;
            valD ? valD : valD = 0;
            valE ? valE : valE = 0;
            result = valA + valB + valC + valD + valE;
            res[bdId] = result;
            break;
        case 6:
            if (is_numberic(valA) && is_numberic(valB)) {
                result = valA + valB;
            } else {
                result = '-';
            }
            break;
        case 7:
            if (is_numberic(valA) && is_numberic(valB) && is_numberic(valC)) {
                result = valA + valB - valC;
                if (result < 0) {
                    $elm.css({
                        'background': '#FF2700',
                        'color': '#fff'
                    });
                } else {
                    $elm.css({
                        'background': '#008000',
                        'color': '#fff'
                    });
                }
            } else {
                result = '-';
            }
            break;
        case 8:
            if (is_numberic(valA) && is_numberic(valB)) {
                result = valA + valB;
                if (result > 200) {
                    $elm.css({
                        'background': '#008000',
                        'color': '#fff'
                    });
                } else {
                    $elm.css({
                        'background': '#FF2700',
                        'color': '#fff'
                    });
                }
            } else {
                result = '-';
            }
            break;
        case 9:
            if (is_numberic(value)) {
                result = parseInt(value);
                if (result > 250 && result < 540) {
                    $elm.css({
                        'background': '#008000',
                        'color': '#fff'
                    });
                } else {
                    $elm.css({
                        'background': '#FF2700',
                        'color': '#fff'
                    });
                }
            } else {
                result = '-';
            }
            break;
        case 10:
            if (is_numberic(value)) {
                result = parseInt(value);
                if (result < 30) {
                    $elm.css({
                        'background': '#008000',
                        'color': '#fff'
                    });
                } else {
                    $elm.css({
                        'background': '#FF2700',
                        'color': '#fff'
                    });
                }
            } else {
                result = '-';
            }
            break;
        case 11:
            if (is_numberic(value)) {
                result = parseInt(value * 10) / 10;
                var resultStr = String(result);
                if (resultStr.length == 2) {
                    result = result + '.0';
                } else {
                    console.log(resultStr.length);
                }
            } else {
                result = '-';
            }
            break;
    }
    return result;
};

var getPressValueTX = function (res, item) {
    var result = 0,
        bdId = item.bdId,
        flag = item.flag,
        threshold = item.threshold,
        valA = res[item['ida']],
        valB = res[item['idb']],
        value = res[bdId];
    switch (flag) {
        case 1:
            if (is_numberic(value)) {
                result = value;
            } else {
                result = '--';
            }
            break;
        case 2:
            if (is_numberic(valA) && is_numberic(valB)) {
                result = parseInt((valA - valB) * 10) / 10;
                judgeBackgroundColor(result, threshold, item);
            } else {
                result = '--';
            }
            break;
        case 3:
            if (is_numberic(value)) {
                result = value + '%';
            } else {
                result = '--';
            }
            break;
        case 4:
            if (is_numberic(valA) && is_numberic(valB)) {
                result = parseInt((valA - valB) * 10) / 10;
                judgeBackgroundColor(result, threshold, item);
                result = result + '%';
            } else {
                result = '--';
            }
            break;
    }
    return result;
};

var getPressValueDD = function (res, item) {
    var result = 0,
        bdId = item.bdId,
        flag = item.flag,
        threshold = item.threshold,
        valA = res[item['ida']],
        valB = res[item['idb']],
        value = res[bdId];
    switch (flag) {
        case 1:
            if (is_numberic(value)) {
                result = value;
                console.log("flag2 result:" + result);
            } else {
                result = '--';
            }
            break;
        case 2:
            if (is_numberic(valA) && is_numberic(valB)) {
                result = parseInt((valA - valB) * 10) / 10;
                console.log("flag2 result:" + result);
                judgeBackgroundColor(result, threshold, item);
            } else {
                result = '--';
            }
            break;
        case 3:
            if (is_numberic(value)) {
                result = value + '%';
            } else {
                result = '--';
            }
            break;
        case 4:
            if (is_numberic(valA) && is_numberic(valB)) {
                result = parseInt((valA - valB) * 10) / 10;
                judgeBackgroundColor(result, threshold, item);
                result = result + '%';
            } else {
                result = '--';
            }
            break;
    }
    return result;
};

var getData = function () {
    $.ajax({
        url: '/Tiexi/api/production_volume?' + Date.now(),
        type: 'GET',
        dataType: 'json',
        success: function (res) {
            $.each(lib, function (index, item) {
                item.$elm.html(getValue(res, item));
            });
        }
    });
};
//从API获取Tiexi PressShop数据函数
var getPressDataTX = function () {
    $.ajax({
        url: '/api/press?type=tx&' + Date.now(),
        type: 'GET',
        dataType: 'json',
        success: function (res) {
            $.each(libPressTX, function (index, item) {
                item.$elm.html(getPressValueTX(res, item));
            });
            // console.log(res);
        }
    });
};
//从API获取Dadong PressShop数据函数
var getPressDataDD = function () {
    $.ajax({
        url: '/api/press?type=dd&' + Date.now(),
        type: 'GET',
        dataType: 'json',
        success: function (res) {
            $.each(libPressDD, function (index, item) {
                console.log(getPressValueDD(res, item));
                item.$elm.html(getPressValueDD(res, item));
            });
            // console.log(res);
        }
    });
};

var getTime = function () {
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    month = checkTime(month);
    day = checkTime(day);
    hour = checkTime(hour);
    minute = checkTime(minute);
    second = checkTime(second);
    var time = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;

    function checkTime(i) {
        if (i < 10) {
            i = "0" + i;
        }
        return i;
    }

    $('.com-time').html(time);
    setTimeout(function () {
        getTime()
    }, 500);
};

var fixPage = function () {
    $.each(urlMark, function (index, item) {
        item.$tabID.click(function () {
            window.location.href = item.mark;
        });
    });
    if (tabId) {
        $.each(urlMark, function (index, item) {
            if (tabId === item.mark) {
                $(".active").removeClass('active');
                item.$tabID.addClass('active');
                item.$tableID.addClass('active in');
            }
        });
    }
    $('.com-tab').on('click', function (e) {
        e.preventDefault();
        $('.active').removeClass('active');
    });
};

var urlMark = [
    {
        tabID: '#Assembly',
        $tabID: $('#tab_Assembly'),
        mark: '#Assembly',
        $tableID: $('#table_Assembly')
    },
    {
        tabID: '#Paint',
        $tabID: $('#tab_Paint'),
        mark: '#Paint',
        $tableID: $('#table_Paint')
    },
    {
        tabID: '#Body',
        $tabID: $('#tab_Body'),
        mark: '#Body',
        $tableID: $('#table_Body')
    },
    {
        tabID: '#Press',
        $tabID: $('#tab_Press'),
        mark: '#Press',
        $tableID: $('#table_Press')
    }
];

$(function () {
    setBackground();
    getData();
    getPressDataTX();
    getPressDataDD();
    getTime();
    fixPage();
    th = setInterval(function () {
        getData();
        getPressDataTX();
        getPressDataDD();
    }, 30000);
    $(window).on('resize', function () {
        setBackground();
    });
    $('.com-nav a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
        setBackground();
        console.log(e.target);
    });
});






